package com.zfast.forge.navigation;

import com.zfast.forge.pojo.CustomBigDecimal;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.math.BigDecimal;

/**
 * 坐标轴
 *
 * @author zgn
 * @Description: Coordinate
 * @date 2022/10/15
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "Coordinate", description = "坐标轴")
public class Coordinate implements Serializable {
    private static final long serialVersionUID = 1L;
    @ApiModelProperty("x")
    public BigDecimal x;
    @ApiModelProperty("y")
    public BigDecimal y;
    @ApiModelProperty("z")
    public BigDecimal z;

    /**
     * x,y,z 字串转坐标系
     * Coordinate Coordinate
     *
     * @param rawCoordinate
     * @return null
     * @auther zgn
     * @date 2022/10/15
     **/
    public Coordinate(String rawCoordinate) {
        String[] parts = rawCoordinate.split(",");

        this.x = CustomBigDecimal.valueOf(parts[0]);
        this.y = CustomBigDecimal.valueOf(parts[1]);
        this.z = CustomBigDecimal.valueOf(parts[2]);
    }

    /**
     * 依据向量[默认,起点(0,0,0)]进行移动
     *
     * @author zgn
     * @date 2024/2/7
     * @param    direction
     * @return com.zfast.forge.navigation.Coordinate
     */
    public Coordinate move(Coordinate direction) {
        return new Coordinate(x.add(direction.x) , y.add(direction.y), z.add(direction.z));
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Coordinate that = (Coordinate) o;

        if (x != that.x) return false;
        if (y != that.y) return false;
        if (z != that.z) return false;

        return true;
    }

    @Override
    public String toString() {
        return x + "," + y + "," + z;
    }
}
